﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SM2TestRunner;

namespace Popups
{
    public partial class EditPanel : Form
    {
        public EditPanel()
        {
            InitializeComponent();
        }

        public static DialogResult ShowEditPanel()
        {
            EditPanel dialog = new EditPanel();
            return dialog.ShowDialog();
        }

        private void btnAddTestcase_Click(object sender, EventArgs e)
        {
            string strDBName = cbbDashboard.SelectedValue.ToString();
            string strSelectedPanelName = cbbExistingPanels.SelectedValue.ToString();
            string strNewPanelItemname = tbNewPanelName.Text.Trim();

            string checkRestoreMaximize = checkBRestoreMaximize.Checked ? "true" : "false";

            InputDispatcher.TEST_PARAMETER = new TestParameters();

            InputDispatcher.TEST_PARAMETER.add("DashBoard Name", strDBName);
            InputDispatcher.TEST_PARAMETER.add("Selected Panel Name", strSelectedPanelName);
            InputDispatcher.TEST_PARAMETER.add("New Panel Name", strNewPanelItemname);
            InputDispatcher.TEST_PARAMETER.add("Check Restore Maximize", checkRestoreMaximize);

            //Update panel item in Panel File
            Repository.TestDataUtil.updateItemNameInFile(strDBName, strSelectedPanelName, strNewPanelItemname);
            this.Close();
        }

        private void EditPanel_Load(object sender, EventArgs e)
        {
            checkBRestoreMaximize.Checked = true;

            #region DASHBOARD
            cbbDashboard.DisplayMember = "Attribute2";
            cbbDashboard.ValueMember = "Attribute1";
            try
            {
                cbbDashboard.DataSource = Repository.ServerHardDataUtil.buildDashboardsDataTable();
            }
            catch (Exception ex)
            {
                Utilities.GlobalObject.LOGGER.log("Failed to load ListBox Dashboard.CHART Utilities.GlobalInit.buildChartTypeDataTable()");
                Utilities.GlobalObject.LOGGER.log(ex.ToString());
            }
            #endregion
        }

        private void cbbDashboard_SelectedIndexChanged(object sender, EventArgs e)
        {
            string strSelectedDBName = cbbDashboard.SelectedValue.ToString();
            #region PANELS
            cbbExistingPanels.DataSource = null;
            if (!strSelectedDBName.Equals(""))
            {
                cbbExistingPanels.DisplayMember = "Column0";
                cbbExistingPanels.ValueMember = "Column0";
                try
                {
                    cbbExistingPanels.DataSource = Repository.TestDataUtil.loadPanelsFromPanelFile(strSelectedDBName);
                }
                catch (Exception ex)
                {
                    Utilities.GlobalObject.LOGGER.log("Failed to load ListBox Dashboard.CHART Utilities.GlobalInit.buildChartTypeDataTable()");
                    Utilities.GlobalObject.LOGGER.log(ex.ToString());
                }
            }
            #endregion
        }

        private void btnDiscard_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
